package UI;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class HomepagePanel extends JPanel implements ActionListener{

	private JButton petButton, eventButton, fosterButton, donationButton, 
					dayButton, monthButton, yearButton, logoutButton;
	
	private MainFrame frame;

	public HomepagePanel(MainFrame mainFrame) {
		
		this.frame = mainFrame;
		
		JLabel logo = new JLabel(" APAC Employee Homepage");
		logo.setFont(new Font("Tahoma", Font.BOLD, 30));
		
		petButton = new JButton("Add New Pet");
		petButton.addActionListener(this);
		eventButton = new JButton("Add New Event");
		eventButton.addActionListener(this);
		fosterButton = new JButton("Assign Pet to a Foster Home");
		fosterButton.addActionListener(this);
		donationButton = new JButton("Donations Report");
		donationButton.addActionListener(this);
		
		dayButton = new JButton("Daily Adoptions Report");
		dayButton.addActionListener(this);
		monthButton = new JButton("Quarterly Adoptions Report");
		monthButton.addActionListener(this);
		yearButton = new JButton("Yearly Adoptions Report");
		yearButton.addActionListener(this);
		
		logoutButton = new JButton("Logout");
		logoutButton.addActionListener(this);
		
        GroupLayout gl = new GroupLayout(this);
		
		gl.setHorizontalGroup(gl.createSequentialGroup()
				.addGap(30)
				.addGroup(gl.createParallelGroup(GroupLayout.Alignment.CENTER)
						.addComponent(logo)
						.addComponent(petButton)
						.addComponent(eventButton)
						.addComponent(fosterButton)
						.addComponent(donationButton)
						.addComponent(dayButton)
						.addComponent(monthButton)
						.addComponent(yearButton)
						.addGroup(gl.createSequentialGroup()
								.addGap(300)
								.addComponent(logoutButton)))
				.addGap(30));
		
	    gl.setVerticalGroup(gl.createSequentialGroup()
	    		.addGap(15)
			    .addComponent(logo)
			    .addGap(40)
			    .addComponent(petButton)
			    .addGap(10)
				.addComponent(eventButton)
				.addGap(10)
				.addComponent(fosterButton)
				.addGap(10)
				.addComponent(donationButton)
				.addGap(40)
				.addComponent(dayButton)
				.addGap(10)
				.addComponent(monthButton)
				.addGap(10)
				.addComponent(yearButton)
				.addGap(20)
				.addComponent(logoutButton)
				.addGap(40)
	    );
		
		gl.setAutoCreateContainerGaps(true);
		gl.setAutoCreateGaps(true);
		
		this.setLayout(gl);
	}
	
	public void paintComponent(Graphics g) {
        super.paintComponents(g);
        g.setColor(Color.blue);
        g.fillRect(0, 0, this.getWidth(), 70);
    }

	public void actionPerformed(ActionEvent e) {
		
		if(e.getSource().equals(logoutButton)) {
			frame.setPanel(frame.getLogin());
		}
		
		else if(e.getSource().equals(petButton)) {
			frame.setPanel(frame.getAddPet());
		}
		
		else if(e.getSource().equals(eventButton)) {
			frame.setPanel(frame.getEvents());
		}
		
		else if(e.getSource().equals(fosterButton)) {
			frame.setPanel(frame.getFoster());
		}
		
		else if(e.getSource().equals(donationButton)) {
			frame.setPanel(frame.getDonations());
		}
		
		else if(e.getSource().equals(dayButton)) {
			frame.setPanel(frame.getDaily());
		}
		
		else if(e.getSource().equals(monthButton)) {
			frame.setPanel(frame.getQuarterly());
		}
		
		else if(e.getSource().equals(yearButton)) {
			frame.setPanel(frame.getYearly());
		}
	}

}
